//
// Created by xili on 2024/9/3 14:34.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    long long largestPerimeter(vector<int> &nums) {
        sort(nums.begin(), nums.end());
        long long pre_sum = 0, ans = -1;
        for (int &x: nums) {
            if (pre_sum > x) ans = max(ans, pre_sum + x);
            pre_sum += x;
        }
        return ans;
    }
};